package edu.hawaii.halealohacli.processor;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.wattdepot.client.WattDepotClient;

/**
 * Tests that QueryProcessor class works correctly.
 * @author Leo deCandia
 */
public class TestQueryProcessor {

  /** The wattdepot client connection. */
  WattDepotClient client;
  
  /**
   * Sets the up connection.
   */
  public void setUp() {
    String url = "http://server.wattdepot.org:8190/wattdepot/";
    client = new WattDepotClient(url);
    assert client.isHealthy();
  }
  
  /**
   * Test that the fake command is found.
   */
  @Test
  public void testQueryProcessor() {
    QueryProcessor queryProcessor = new QueryProcessor(client);
    assertNotNull("null QueryPocessor reference returned", queryProcessor);
    assertNotNull("registry not update to contain fake-command entry",
        queryProcessor.registry.get("fake-command"));
  }

  /**
   * Test that the fake command can be invoked.
   */
  @Test
  public void testInvokeCommandByName() {
    QueryProcessor queryProcessor = new QueryProcessor(client);
    boolean invoked = 
        queryProcessor.invokeCommandByName("fake-command", new String[]{"aabc", "bb", "ccc"});
    assertTrue("could not invode fake-command command", invoked);
  }

}
